#define _CRT_SECURE_NO_WARNINGS
#include"Queue.h"
void QueueInit(Queue* q)
{
	q->head = q->tail = NULL;
	q->size = 0;
}
void QueueDestroy(Queue* q)
{
	QueueNode* cur = q->head;
	while (cur)
	{
		QueueNode* tmp = cur->next;
		free(cur);
		cur = tmp;
	}
	q->head = q->tail = NULL;
	q->size = 0;
}
void QueuePush(Queue* q, QDateType x)
{
	QueueNode* tmp = (QueueNode*)malloc(sizeof(QueueNode));
	if (tmp == NULL)
	{
		perror("Malloc Failed");
		return;
	}
	tmp->date = x;
	tmp->next = NULL;
	if (!q->head)
	{
		q->head= tmp;
		q->tail = tmp;
	}
	else
	{
		q->tail->next = tmp;
		 q->tail= tmp;
	}
	q->size++;
}
void QueuePop(Queue* q)
{
	assert(!QueueEmpty(q));
	assert(q->head != NULL);
	if (!q->head->next)
	{
		free(q->head);
		q->head = q->tail = NULL;
	}
	else
	{
		QueueNode* next = q->head->next;
		free(q->head);
		q->head = next;
	}
	q->size--;

}
bool QueueEmpty(Queue* q)
{
	assert(q);
	return q->size == 0;
}
int QueueSize(Queue* q)
{
	assert(q);
	return q->size;
}
QDateType QueueFront(Queue* q)
{
	assert(q);
	assert(!QueueEmpty(q));
	return q->head->date;
}
QDateType QueueBack(Queue* q)
{
	assert(q);
	assert(!QueueEmpty(q));
	return q->tail->date;
}